import axios from 'axios';
import { getToken } from '../utils/auth';

const service = axios.create({
    baseURL: 'http://127.0.0.1:8080',
    timeout: 5000
});
// 请求拦截器
service.interceptors.request.use(config => {
    // Do something before request is sent
    config.headers['token'] =getToken();
    return config;
}, error => {
    // Do something with request error
    console.log(error); 
    return Promise.reject(error);
});
// 响应拦截器
service.interceptors.response.use(response => {
    // Do something with response data
    // console.log(response);
    return response;
}, error => {
    // Do something with response error
    console.log(error);
    return Promise.reject(error);
});

export default service;